Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RigidDynamicBody gaining momentum with bounce #55313

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

pouleyKetchoupp
Copy link
Contributor

Bounce calculation now uses the previous frame's velocity, so it's consistent with the actual motion of the bodies involved and not the yet-to-be-applied forces.

This is due to the order of update in the solver:

  1. Integrate forces (update velocity from applied forces and gravity)
  2. Solve contacts separation and bounce (update velocity from contacts)
  3. Integrate velocity (update position from velocity) -> so this velocity is actually used to generate next frame's contacts and should be used for bounce calculation

When bounce is 1, using the current velocity was causing the new forces (including gravity) to be taken into account, which lead to the bounce velocity to be higher than the falling velocity at the moment of impact, adding more and more energy over time.

This change can be considered compatibility breaking, because it changes the effect of bounce and might require users to modify their physics material or damping settings to keep the same behavior in some cases.

Fixes #25186 (tested with MRP from #24332)
Fixes #52550
Helps with #29639 but doesn't fix it completely, as contacts are still adding energy.

Bounce calculation now uses the previous frame's velocity, so it's
consistent with the actual motion of the bodies involved and not the
yet-to-be-applied forces.

When bounce is 1, using the current velocity was causing the new forces
(including gravity) to be taken into account, which lead to the bounce
velocity to be higher than the falling velocity at the moment of impact,
adding more and more energy over time.
@akien-mga akien-mga merged commit dc585e2 into godotengine:master Nov 25, 2021
@akien-mga
Copy link
Member

Thanks!

@pouleyKetchoupp pouleyKetchoupp deleted the bounce-energy-stability branch November 26, 2021 01:17
@belzecue
Copy link

belzecue commented Apr 15, 2023

This is such an important fix for 3.x 2D physics (physics materials) that leaving it out due to compat-breaking worries is not, in my view, reasonable.

I battled for several nights recently trying to understand why bounce caused continuous jitter in 3.5.2 2D physics. After seeing the various known recorded bugs around this issue, I finally concluded that it's best to use physics materials with bounce very, very sparingly, e.g. only in a few surfaces, and keeping the bounce value below 0.5 to reduce the infinite jitter dance.

I would like to see this important fix backported to 3.x and set as default OFF in settings, so that it will not affect existing games, but can be used by new projects.

My blog post about this here: https://godotyourself.blogspot.com/2023/04/hold-my-beer.html

Linux and Windows builds of 3.5.2 with the fix here: https://github.com/belzecue/godot-af/releases/tag/3.5.2-stable-af-phys-bounce-fix

UPDATE: PR for backporting this change to 3.x: #76216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants